import {
    addBargainOrder
} from "@/lib/api/bargainServer/initiator";
import payMixin from "@/mixins/pay";
export default {
    mixins: [payMixin],
    data() {
        return {}
    },

    methods: {
        
        // 付款
        async nowPay(bargainInitiatorId, orderId = '') {

            try {
                orderId = orderId || (await this.createBargainOrder(bargainInitiatorId));
            } catch (error) {
                console.log("error", error);
                await this.$api.showToast(error.resultInfo || "操作失败");
                return;
            }

            try {
                await this.onPay(orderId);
                uni.redirectTo("/pages/user/pages/order/orderList");
            } catch (error) {
                console.log("error", error);
                this.$api.showToast(error.resultInfo || "支付失败");
                uni.reLaunch({
                    url: "/pages/user/pages/order/orderList"
                });
            }
        },
        // 创建付款订单
        createBargainOrder(bargainInitiatorId) {
            const propsData = {
                bargainInitiatorId
            };

            return addBargainOrder(propsData).then(res => {
                return res.data.orderId;
            });
        },
    },
}